package com.zjsru.oneDay;

import java.util.Arrays;

/**
 * 替换所有问号
 * <p>
 * 输入：s = "?zs"
 * 输出："azs"
 * 解释：该示例共有 25 种解决方案，从 "azs" 到 "yzs" 都是符合题目要求的。只有 "z" 是无效的修改，因为字符串 "zzs" 中有连续重复的两个 'z' 。
 * <p>
 * <p>
 * 输入：s = "??yw?ipkj?"
 * 输出："acywaipkja"
 */
public class modifyString {
    public String modifyString(String s) {
        char[] cs = s.toCharArray();
        int n = cs.length;
        for (int i = 0; i < n; i++) {
            if (cs[i] == '?') {
                for (char ch = 'a'; ch <= 'c'; ch++) {
                    if (i > 0 && cs[i - 1] == ch || i < n - 1 && cs[i + 1] == ch) {
                        continue;
                    }
                    cs[i] = ch;
                    break;
                }
            }
        }
        return new String(cs);
    }

    public static void main(String[] args) {
        modifyString modifyString = new modifyString();
        String s = "j?qg??b";
        System.out.println(modifyString.modifyString(s));
    }
}
